package com.hdax.dm.rest.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hdax.dm.dao.user.DmUserMapper;
import com.hdax.dm.entity.user.DmLinkUser;
import com.hdax.dm.entity.user.DmUser;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

@RestController
@RequestMapping(path = "/user")
@Api(value = "用户测试接口",tags = "用户测试接口")
public class DmUserRestService {

    @Resource
    private DmUserMapper dmUserMapper;

    @ApiOperation(value = "根据手机号查询用户信息")
    @PostMapping(path = "/findByPhone")
    public DmUser findByPhone(@RequestParam("phoneNumber")String phoneNumber){
        QueryWrapper<DmUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("phone",phoneNumber);
        return dmUserMapper.selectOne(queryWrapper);
    }

    @ApiOperation(value = "根据用户id查询用户信息")
    @PostMapping(path = "/findById")
    public DmUser findById(@RequestParam("id")Long id){
        QueryWrapper<DmUser> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id",id);
        return dmUserMapper.selectOne(queryWrapper);
    }

    //修改用户信息
    @PostMapping(path = "/updateUserInfo")
    public int updateUserInfo(@RequestBody DmUser dmUser){
        System.out.println(dmUser);
        return dmUserMapper.updateById(dmUser);
    }

    //添加用户
    @PostMapping(path = "/addUserInfo")
    public int addUserInfo(@RequestBody DmUser dmUser){
        return dmUserMapper.insert(dmUser);
    }

}
